package com.jic.manager.controller.manage.merchant;


import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.manager.entity.MerchantChannel;
import com.jic.manager.request.MerchantChannelRequest;
import com.jic.manager.service.MerchantChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 渠道
 * @autho wwb
 */
@RestController
@RequestMapping("merchantChannel")
public class MerchantChannelController {
    @Autowired
    private MerchantChannelService merchantChannelService;
    //查询列表
    @PostMapping(value = "/queryMerchantChannelInfo")
    public RestResult<MerchantChannel> queryInfo(@RequestBody MerchantChannel mchannel){
        MerchantChannel merchantChannel  = merchantChannelService.queryByPrimaryKey(mchannel.getId());
        return RestResult.success(merchantChannel);
    }

    //查询列表
    @PostMapping(value = "/queryMerchantChannelListOther")
    public RestResult<List<MerchantChannel>> queryMerchantChannelListOther(@RequestBody MerchantChannel mchannel){
        List<MerchantChannel> merchantChannels  = merchantChannelService.query(mchannel);
        return RestResult.success(merchantChannels);
    }

    //查询列表
    @PostMapping(value = "/queryMerchantChannelList")
    public RestResult<PageResult<MerchantChannel>> queryMerchantChannelList(@RequestBody MerchantChannelRequest mchannelRequest){
        MerchantChannel merchantChannel = new MerchantChannel();
        BeanUtils.copyProperties(mchannelRequest,merchantChannel);
        PageResult<MerchantChannel> merchantChannelPageResult = merchantChannelService.queryPage(merchantChannel, new Page() {{
            setStart(mchannelRequest.getStart());
            setLimit(mchannelRequest.getLimit());
        }});
        return RestResult.success(merchantChannelPageResult);
    }

    //编辑方法
    @PostMapping(value = "/editMerchantChannelInfo")
    public RestResult<String> editMerchantInfo(@RequestBody MerchantChannelRequest mchannel){
        return merchantChannelService.editMerchantChannelInfo(mchannel);
    }
}
